
//
//  Status.swift
//  Weibo
//
//  Created by 张婷 on 15/10/23.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    /// 用户账户
    var user: User?
    
    /// 微博创建时间
    var created_at: String?
    
    /// 微博ID
    var id: Int = 0
    
    /// 微博来源
    var source: String?
    
    /// 微博信息内容
    var text: String?
    
    /// 缩略图片字典数组
    var pic_urls: [[String: String]]?
    
    /// 被转发的原微博信息字段
    var retweeted_status: Status?
    
    
    /// MARK: 构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = User(dict: dict)
            }
            return
        }
        
        ///  转发微博
        if key == "retweeted_status" {
            
            if let dict = value as? [String: AnyObject] {
                retweeted_status = Status(dict: dict)
            }
            return
        }
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["created_at", "id", "source", "text", "user", "pic_urls", "retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
